<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\facade\View;
use think\response\Json;

class Index extends AdminBase
{
    public function index(): string
    {
        $merchantUserObj = new \app\platform\business\Merchant();
        $merchant        = $merchantUserObj->getMerchantUserFromSession();
        $menuBusiness    = new \app\common\business\Menu();
        $menus           = $menuBusiness->getBackendPermissionMenus($merchant['roleIds']);
        View::assign([
            'merchant' => $merchant,
            'menus'    => $menus,
        ]);

        return View::fetch();
    }

    public function console(): string
    {
        $list = $this->request->param("list", 0, 'intval');
        View::assign(['list' => $list]);
        return View::fetch();
    }

    public function doCache():Json
    {
        $attributeBusiness = new \app\common\business\Attribute($this->websiteCode);
        $attributeBusiness->clearAttributeCache();

        $attributeValueBusiness = new \app\common\business\AttributeValue($this->websiteCode);
        $attributeValueBusiness->clearAttributeValueCache();

        $categoryBusiness = new \app\common\business\Category($this->websiteCode);
        $categoryBusiness->clearCategoryCache();

        $feedbackFieldBusiness = new \app\admin\business\FeedbackField($this->websiteCode);
        $feedbackFieldBusiness->clearFeedbackFieldCache();

        $moduleBusiness = new \app\common\business\Module($this->websiteCode);
        $moduleBusiness->clearModuleCache();

        $moduleFieldBusiness = new \app\common\business\ModuleField($this->websiteCode);
        $moduleFieldBusiness->clearModuleFieldCache();

        return show(config(self::_CONFIG_STATUS_SUCCESS_CODE), 'success');
    }
}
